/*     */ package com.wzh.action.tag;
/*     */ 
/*     */ import com.wzh.bean.book.BookChapter;
/*     */ import com.wzh.service.bookinfo.chapter.BookChapterService;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletResponse;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.jsp.JspException;
/*     */ import javax.servlet.jsp.PageContext;
/*     */ import javax.servlet.jsp.tagext.TagSupport;
/*     */ import org.apache.struts2.ServletActionContext;
/*     */ import org.springframework.web.context.WebApplicationContext;
/*     */ import org.springframework.web.context.support.WebApplicationContextUtils;
/*     */ 
/*     */ public class ChapterTag extends TagSupport
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  24 */   private int num = 10;
/*     */   private Integer bookid;
/*  26 */   private String order = "";
/*     */   private String var;
/*  28 */   private int start = 0;
/*  29 */   private int page = 0;
/*     */   private Iterator<BookChapter> it;
/*  33 */   private int i = 0;
/*     */ 
/*     */   public String getVar()
/*     */   {
/*  41 */     return this.var;
/*     */   }
/*     */ 
/*     */   public void setVar(String var)
/*     */   {
/*  46 */     this.var = var;
/*     */   }
/*     */ 
/*     */   public int getNum()
/*     */   {
/*  51 */     return this.num;
/*     */   }
/*     */ 
/*     */   public void setNum(int num) {
/*  55 */     this.num = num;
/*     */   }
/*     */ 
/*     */   public int getStart()
/*     */   {
/*  61 */     return this.start;
/*     */   }
/*     */ 
/*     */   public void setStart(int start)
/*     */   {
/*  66 */     this.start = start;
/*     */   }
/*     */ 
/*     */   public String getOrder()
/*     */   {
/*  71 */     return this.order;
/*     */   }
/*     */ 
/*     */   public void setOrder(String order) {
/*  75 */     this.order = order;
/*     */   }
/*     */ 
/*     */   private void init()
/*     */   {
/*  81 */     String pageStr = ServletActionContext.getRequest().getParameter("page");
/*  82 */     String bookidStr = ServletActionContext.getRequest().getParameter("bookid");
/*     */ 
/*  84 */     if ((bookidStr == null) && (!"".equals(bookidStr))) {
/*  85 */       return;
/*     */     }
/*  87 */     this.bookid = Integer.valueOf(Integer.parseInt(bookidStr));
/*     */ 
/*  92 */     int firstindex = -1;
/*  93 */     if ((pageStr != null) && (!"".equals(pageStr))) {
/*  94 */       this.page = Integer.parseInt(pageStr);
/*  95 */       firstindex = (this.page - 1) * this.num + this.start;
/*     */     }
/*     */ 
/* 118 */     WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
/* 119 */     BookChapterService chapterService = (BookChapterService)wac.getBean("bookChapterServiceBean");
/* 120 */     List chapters = chapterService.getChapters(this.bookid, firstindex, this.num, this.order);
/* 121 */     this.it = chapters.iterator();
/*     */   }
/*     */ 
/*     */   public int doStartTag()
/*     */     throws JspException
/*     */   {
/* 132 */     init();
/*     */ 
/* 135 */     this.pageContext.getResponse().setCharacterEncoding("utf-8");
/* 136 */     if ((this.it != null) && (this.it.hasNext())) {
/* 137 */       this.i += 1;
/* 138 */       this.pageContext.setAttribute(this.var, this.it.next());
/* 139 */       this.pageContext.setAttribute("i", Integer.valueOf(this.i));
/* 140 */       return 1;
/*     */     }
/* 142 */     return 0;
/*     */   }
/*     */ 
/*     */   public int doAfterBody() throws JspException
/*     */   {
/* 147 */     if ((this.it != null) && (this.it.hasNext())) {
/* 148 */       this.i += 1;
/* 149 */       this.pageContext.setAttribute(this.var, this.it.next());
/* 150 */       this.pageContext.setAttribute("i", Integer.valueOf(this.i));
/* 151 */       return 2;
/*     */     }
/* 153 */     return 0;
/*     */   }
/*     */ 
/*     */   public int doEndTag()
/*     */     throws JspException
/*     */   {
/* 160 */     this.i = 0;
/* 161 */     this.pageContext.removeAttribute(this.var);
/* 162 */     this.pageContext.removeAttribute("i");
/* 163 */     return 6;
/*     */   }
/*     */ }

/* Location:           C:\work\apache-tomcat-7.0.55\webapps\ROOT\WEB-INF\classes\
 * Qualified Name:     com.wzh.action.tag.ChapterTag
 * JD-Core Version:    0.6.1
 */